<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Quiz/classes/PhpFox_ComponentAllResults.class.php, $Author:  $ */



/** List of quizzes
 * 
 *   
 * @version $Id: PhpFox_ComponentAllResults.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.quiz
 */
class PhpFox_Mod_Quiz_ComponentAllResults extends BaseComponent
{
    function process()
    {
        $oSrvQuiz = &$this->_oModule->getService('Quiz');
        /* @var $oSrvQuiz PhpFox_Mod_Quiz_ServiceQuiz */
        
        $oReq = &App::getRequest();
        /* @var $oReq Request */
        
        $oSrvSec = &App::getModuleService('Account', 'Security');
        /* @var $oSrvSec PhpFox_Mod_Account_ServiceSecurity */
        
        $iQuizId = $oReq->getInt('id');
        
        $oQuiz = &$this->_oModule->getItem('Quiz');
        if (!$oQuiz->load($iQuizId))
        {
            //no such quiz (or no id parmas)
            App::gotoUrl('public.quiz');
        }
        
        $oUser = $oSrvSec->getCurrentUser();
        if ( !($oUser &&
               ($oSrvQuiz->isPassedQuiz($oUser, $iQuizId) || ($oQuiz->aData['user']==$oUser->aData['user']))
           ) )
        {
            App::gotoUrl('public.quiz.take', array('id' => $iQuizId));
        }
        
        $iPage = $oReq->get('page', 1);
        $iPageSize = App::getParam('public.pagesize');
        
        $aCond = array();
        $sSort = '`time`';
        list($aQuizResults, $iCnt) = $oSrvQuiz->getQuizResultsList($iQuizId, $iPage, $iPageSize, $sSort);
        $oPager = App::newObject('Pager', $iCnt, $iPage, $iPageSize);
        
        $oTpl = &$this->_oModule->getTemplate();
        $oTpl->assign(array(
            'aQuiz'       => $oQuiz->aData,
            'aResults'    => $aQuizResults,
            'sUserPicUrl' => App::getParam('user.pic.url'),
            'aPaging'     => $oPager->getInfo(App::getUrl()),
        ));
        return $oTpl->fetch('AllResults.html');
    }
}
?>